<template>
	<xn-form-container
		title="配课参数"
		:width="700"
		:visible="visible"
		:destroy-on-close="true"
		:show-pagination="false"
		@close="onClose"
	>
		<a-form ref="formRef" :model="formData" :rules="formRules" layout="vertical">
			<a-form-item label="专业：" name="major">
				<a-select v-model:value="formData.major" placeholder="请选择专业" :options="majorOptions" />
			</a-form-item>
			<a-form-item label="学生分类：" name="studentType">
				<a-select v-model:value="formData.studentType" placeholder="请选择分类" :options="studentTypeOptions" />
			</a-form-item>
			<a-form-item label="年级：" name="grade">
				<a-input-number v-model:value="formData.grade" placeholder="请输入年级" allow-clear style="width: 25%" min="2022" />
			</a-form-item>
		</a-form>
		<template #footer>
			<a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
			<a-button type="primary" @click="onSubmit" :loading="submitLoading">保存</a-button>
		</template>
	</xn-form-container>
</template>

<script setup name="Choice">
	import { cloneDeep } from 'lodash-es'
	import { required } from '@/utils/formRules'
	import eduCourseApi from '@/api/biz/eduCourseApi'
	import tool from '@/utils/tool'
	import eduTutorialApi from '@/api/biz/eduTutorialApi'
	// 抽屉状态
	const visible = ref(false)
	const emit = defineEmits({ successful: null })
	const formRef = ref()
	// 专业数据
	let majorOptions = ref()
	// 学生分类
	let studentTypeOptions = ref()
	// 表单数据
	const formData = ref({})
	const submitLoading = ref(false)

	// 打开抽屉
	const onOpen = (record) => {
		visible.value = true
		if (record) {
			let recordData = cloneDeep(record)
			formData.value = Object.assign({}, recordData)
		}
		studentTypeOptions.value = tool.dictList('STUDENT_TYPE')
		majorOptions.value = tool.dictList('MAJOR')
	}
	// 关闭抽屉
	const onClose = () => {
		formRef.value.resetFields()
		studentTypeOptions.value = []
		majorOptions.value = []
		visible.value = false
	}
    const filterOption = (input, option) => {
		return option.name.toLowerCase().indexOf(input.toLowerCase()) >= 0;
    }
	// 默认要校验的
	const formRules = {}
	// 验证并提交数据
	const onSubmit = () => {
		if (!formData.value.studentType) {
			formData.value.studentType = null
		}
		if (!formData.value.major) {
			formData.value.major = null
		}
		if (!formData.value.grade) {
			formData.value.grade = null
		}
		emit('submit', formData.value.major, formData.value.studentType, formData.value.grade)
		onClose()
	}
	// 抛出函数
	defineExpose({
		onOpen
	})
</script>
